<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="dk.itu.iwjx.beans.*" %>
<%@ page errorPage="global/error.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<jsp:useBean id="item" scope="page" class="dk.itu.iwjx.beans.ItemBean" />

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<body>
	<h3>handle basket operation here...</h3>

	<%  Map<Integer,ItemBean>  basket;
		if(session.isNew()){
			basket=new HashMap<Integer,ItemBean>();
			session.setAttribute("basket",basket);
		}else{
			basket=(Map<Integer,ItemBean>)session.getAttribute("basket");
			String oper=request.getParameter("oper");
			int id=Integer.parseInt(request.getParameter("id"));
			if(oper.equals("add")){
				if(basket.containsKey(id))
					basket.get(id).setQuantity(basket.get(id).getQuantity()+1);
				else{item.setPizzaId(id);
					item.setQuantity(1);
					basket.put(item.getPizzaId(),item);
				}
			}else if(oper.equals("remove")){
				basket.remove(id);
			}else if(oper.equals("update")){
				int quat=Integer.parseInt(request.getParameter("quat"));
				ItemBean ib=(ItemBean)basket.get(id);
				ib.setQuantity(ib.getQuantity()+quat);
			}
		}
	%>
	<% response.sendRedirect("index.jsp");%>
</body>
</html>